package icu.lookyousmileface.concurrentutils;

import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.FutureTask;

/**
 * @author starrysky
 * @title: CountDownLatchUse
 * @projectName Juc_Pro
 * @description: CountDownLatch辅助类常用必会
 * @date 2021/1/292:13 下午
 */
public class CountDownLatchUse {
    public static void main(String[] args) {
        CountDownLatch countDownLatch = new CountDownLatch(6);

        for (int i = 1; i <=6; i++) {
            new Thread(new FutureTask<Integer>(()-> {
                System.out.println(Thread.currentThread().getName()+":"+"走出教室！");
                countDownLatch.countDown();
                return 1024;}),String.valueOf(i)).start();
        }
        try {
            countDownLatch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("全员已经都离开来教室，教室大门锁上！！！");
    }
}
